package com.lian.community.async.handler;

import com.lian.community.async.EventHandler;
import com.lian.community.async.EventModel;
import com.lian.community.constant.EventType;
import com.lian.community.entity.mail.Email;
import com.lian.community.entity.mail.EmailAddress;
import com.lian.community.util.MailUtil;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;

@Component
public class RegisterHandler implements EventHandler {
    @Override
    public void doHandler(EventModel eventModel) {
        String title = "lovingpet邮箱验证";
        EmailAddress from = new EmailAddress("lovingpet","lian@lovingpet.top");
        Email email = new Email()
                .from(from)
                .to(new EmailAddress[]{(new EmailAddress("769025704@qq.com", "769025704@qq.com"))})
                .title(title)
                .content("test")
                .contentType("text/html;charset=UTF-8")
                .encoding("UTF-8");
        try {
            MailUtil.sendEmail("lian@lovingpet.top","LOVINGpet123", email);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }

    @Override
    public List<EventType> geSupportEvent() {
        return Arrays.asList(EventType.REGISTER);
    }
}
